<?php
    $resLink = mysqli_connect("localhost", "root", "", "user");
    if (! $resLink) {
        $err = mysqli_error($resLink);
        if ($err) {
            exit();
        }
    }
    $username = $_POST["username"];
    $password = $_POST["password"];
    $repeatedpassword = $_POST["repeatedpassword"];
    mysqli_query($resLink, "set character set utf8 ");
    mysqli_query($resLink, "set character_set_results =utf8 ");
    if($username && $password && $repeatedpassword){
        if(strcmp($password, $repeatedpassword)){
            echo "2";   //密码与重复密码不一致
            exit;
        }
        $qString = "select * from userinfo where username = '$username'";
        $Query_ID = mysqli_query($resLink, $qString);
        $rows = mysqli_num_rows($Query_ID);
        if(!$rows){
            $qString = "insert into userinfo(username,password) values('$username','$password')";
            $Query_ID = mysqli_query($resLink, $qString);
            echo '1';
        }
        else {
            echo "3";    //用户名已存在
        }
    }
    else{
        echo "0";     //所有信息不准为空
    }
?>